package com.zhengxuetao.website.controller;
import com.zhengxuetao.website.req.EbookQueryReq;
import com.zhengxuetao.website.resp.CommonResp;
import com.zhengxuetao.website.resp.EbookResp;
import com.zhengxuetao.website.resp.PageResp;
import com.zhengxuetao.website.service.EbookService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ebook")
public class EbookController {

    @Resource
    private EbookService ebookService;
    @GetMapping("/list")
    public CommonResp list(@Valid EbookQueryReq req) {
        CommonResp<PageResp<EbookResp>> resp = new CommonResp<>();
        PageResp<EbookResp> list = ebookService.list(req);
        resp.setContent(list);
        return resp;
    }
    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookResp req){
        CommonResp resp = new CommonResp<>();
        ebookService.save(req);
        return resp;
    }

    @DeleteMapping("/delete/{id}")
public CommonResp delete(@PathVariable Long id){
    CommonResp resp = new CommonResp<>();
    ebookService.delete(id);
    return resp;
}
}

